package com.webservice.xmloper.managercode;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class KeywordRangeConvertor implements Converter{

	public void marshal(Object source, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		KeywordRange keywordRange = null;
		if(source != null ){
			keywordRange = (KeywordRange) source;
		}
		if(keywordRange != null && keywordRange.getKeywordRage() != null){
			writer.setValue(keywordRange.getKeywordRage());
		}else{
			writer.setValue("");
		}
		
	}

	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		KeywordRange keywordRange = new KeywordRange();
		try{
			keywordRange.setKeywordRage(reader.getValue());
		}catch(Exception e){
			e.printStackTrace();
			keywordRange.setKeywordRage(null);
		}
        return keywordRange;
	}

	public boolean canConvert(Class type) {
		 return type.equals(KeywordRange.class);
	}

}
